'''
Uses JSMin. Python version available from http://www.crockford.com/javascript/jsmin.py.txt

Provides template tags to minify JavaScript on the fly.

{% minifyjs %}[code]{% endminifyjs %} 
'''
from django import template
from {{project_name}}.utils.jsmin import jsmin

register = template.Library()


class MinifyJs(template.Node):
    def __init__(self, nodelist):
        self.nodelist = nodelist
    def render(self, context):
        return jsmin(self.nodelist.render(context))
    
@register.tag
def minifyjs(parser, token):
    nodelist = parser.parse(('endminifyjs',))
    parser.delete_first_token()
    return MinifyJs(nodelist)
